package org.dromara.system.domain.vo;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.common.sensitive.annotation.Sensitive;
import org.dromara.common.sensitive.core.SensitiveStrategy;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import org.dromara.system.domain.SysStore;
import org.dromara.system.domain.SysUser;

import java.io.Serial;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 用户信息视图对象 sys_user
 *
 * @author Michelle.Chung
 */
@Data
@AutoMapper(target = SysUser.class)
public class SysUserVo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */

    private Long userId;

    private String userIdStr;

    /**
     * 租户ID
     */
    private String tenantId;

    /**
     * 部门ID
     */
    private Long deptId;

    /**
     * 用户账号
     */
    private String userName;

    /**
     * 用户昵称
     */
    private String nickName;

    /**
     * 用户类型（sys_user系统用户）
     */
    private String userType;

    /**
     * 用户邮箱
     */
//    @Sensitive(strategy = SensitiveStrategy.EMAIL)
    private String email;

    /**
     * 手机号码
     */
//    @Sensitive(strategy = SensitiveStrategy.PHONE)
    private String phonenumber;

    /**
     * 用户性别（0男 1女 2未知）
     */
    private String sex;

    /**
     * 头像地址
     */
    @Translation(type = TransConstant.OSS_ID_TO_URL)
    private Long avatar;

    /**
     * 密码
     */
    @JsonIgnore
    @JsonProperty
    private String password;

    /**
     * 帐号状态（0正常 1停用）
     */
    private String status;

    /**
     * 最后登录IP
     */
    private String loginIp;

    /**
     * 最后登录时间
     */
    private Date loginDate;

    /**
     * 备注
     */
    private String remark;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 部门组部门对象
     */
    private List<SysDeptVo> depts;

    /**
     * 角色对象
     */
    private List<SysRoleVo> roles;

    private List<SysStoreVo> stores;


    private List<Long> storeIds;


    private List<Long> areaIds;

    private List<Long> deviceIds;


    public List<Long> getDeptIds() {
        List<SysDeptVo> deptList = this.depts;
        if (CollectionUtils.isEmpty(deptList)) {
            return Collections.emptyList();
        }
        return deptList.stream().map(SysDeptVo::getDeptId).collect(Collectors.toList());
    }



    public String getDeptNames() {
        List<SysDeptVo> deptList = this.depts;
        if (CollectionUtils.isEmpty(deptList)) {
            return "";
        }
        return deptList.stream()
                .map(SysDeptVo::getDeptName)
                .collect(Collectors.joining(","));
    }


    public String getStoreNames() {
        List<SysStoreVo> deptList = this.stores;
        if (CollectionUtils.isEmpty(deptList)) {
            return "";
        }
        return deptList.stream()
                .map(SysStoreVo::getStoreName)
                .collect(Collectors.joining(","));
    }

    public String getRoleNames() {
        List<SysRoleVo> rolesList = this.roles;
        if (CollectionUtils.isEmpty(rolesList)) {
            return "";
        }
        return rolesList.stream()
                .map(SysRoleVo::getRoleName)
                .collect(Collectors.joining(","));
    }

}
